<?php
/**
 * Project: Recipe
 * File: FoodArticleModel.class.php
 * Author: Xnfy520@gmail.com
 * Date: 12-4-18
 * Time: 下午12:56
 */

	class FoodArticleModel extends RelationModel{

		protected $_validate = array(
			array('name', 'require', '食材名称不能为空', 1, 'regex', 3),
			array('sort', 'number', '排序必须为数字', 1, 'regex', 3),
		);

		protected $_auto = array(
			array('created', 'time', 1, 'function'), //发表时间
		);

		protected $_link = array(

			'FoodCategory'=>array(
				'mapping_type'=>BELONGS_TO,
				'mapping_name'=>'foodcategory',
				'class_name'=>'FoodCategory',
				'foreign_key'=>'categoryid',
			),

			'FoodSection'=>array(
				'mapping_type'=>BELONGS_TO,
				'mapping_name'=>'foodsection',
				'class_name'=>'FoodSection',
				'foreign_key'=>'sectionid',
			),

			'FoodNutritions'=>array(
				'mapping_type'=>HAS_ONE,
				'mapping_name'=>'foodnutritions',
				'class_name'=>'FoodNutritions',
				'foreign_key'=>'articleid',
				'mapping_fields'=>'id',
			),

			'FoodDeal'=>array(
				'mapping_type'=>HAS_ONE,
				'mapping_name'=>'fooddeal',
				'class_name'=>'FoodDeal',
				'foreign_key'=>'articleid',
				'mapping_fields'=>'unit,deal',
			),

//			'FoodCollocation'=>array(
//				'mapping_type'=>HAS_ONE,
//				'mapping_name'=>'foodcollocation',
//				'class_name'=>'FoodCollocation',
//				'foreign_key'=>'articleid',
//			),

		);

	}
